<template>
    <div class="sortingTableBox">
        <div>
            <el-button size="mini" type="primary" @click="searchBtn">查询</el-button>
            <el-button size="mini" type="primary" @click="taskBtn">分配任务</el-button>
            <el-button size="mini" type="primary" @click="onLineBtn">分拣台上线</el-button>
            <el-button size="mini" type="primary" @click="offLineBtn">分拣台下线</el-button>
        </div>
        <TableTitle style="margin-top:5px">
            <slot>
                <p>
                    分拣台信息列表
                </p>
            </slot>
        </TableTitle>
        <div class="tableBOx">
            <el-table
                ref="receiveTable"
                size="mini"
                :data="resData"
                style="width: 100%"
                @selection-change="handleSelectionChange"
                highlight-current-row
            >
            <!-- <el-table-column type="selection" width="40"> </el-table-column> -->
            <el-table-column type="index" label="序号" width="50" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="SORTINGTABLENAME" label="分拣台名称"  :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="SORTINGTABLEIP" label="分拣台IP地址"  :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="SORTINGTABLESTATUS" label="分拣台状态"  :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="SORTINGTABLENO" label="分拣台编号"  :show-overflow-tooltip="true"> </el-table-column>
            </el-table>
            <!-- 分页 -->
            <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="pageNumber"
                :page-sizes="[10, 20, 50, 100]"
                :page-size="pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="totalCount"
            >
            </el-pagination>
        </div>
    </div>
</template>
<script>
import { sysSortTableData,sysSortTableTask,sysSortTableOnline,sysSortTableOffline } from "@/utils/api.js"
import TableTitle from "../../../../../components/TableTitle.vue";
export default {
    name:'',
    components:{
        TableTitle
    },
    data(){
        return{
            pageSize:20,
            pageNumber:1,
            totalCount:0,
            resData:[]
        }
    },
    methods:{
        // 勾选函数
        handleSelectionChange(val) {
            console.log(val)
        },
        // 选择每页条数后请求接口更新表格
        handleSizeChange(val) {
        this.pageSize = val;
        // 刷新本表
        this.$options.methods.searchBtn.bind(this)()
        },
        // 分页函数
        handleCurrentChange(val) {
        this.pageNumber = val;
        // 刷新本表
        this.$options.methods.searchBtn.bind(this)()
        },
        searchBtn(){
           sysSortTableData({
                pageParameter:{
                    rows:this.pageSize,
                    page:this.pageNumber
                }
            }).then((res)=>{
                console.log('数据查询',res)
                if(res.data.retCode == 200){
                    this.resData = res.data.responseBody.result
                    this.totalCount = res.data.responseBody.pageParameter.totalCount
                }else{
                    this.$Alert({
                        title: "失败",
                        message: res.data.message,
                        type: "error",
                    });
                }
            }) 
        },
        taskBtn(){
            sysSortTableTask({

            }).then((res)=>{
                console.log('分配任务',res)
                if(res.data.retCode == 200){
                    // 刷新本表
                    this.$options.methods.searchBtn.bind(this)()
                    // 分拣台管理刷新工作包任务列表
                    this.$bus.$emit('sortManDoGzbsmData','reTable')
                    this.$Alert({
                        title: "成功",
                        message: res.data.message,
                        type: "success",
                    });
                }else{
                    this.$Alert({
                        title: "失败",
                        message: res.data.message,
                        type: "error",
                    });
                }
            })
        },
        onLineBtn(){
            sysSortTableOnline({

            }).then((res)=>{
                console.log('上线',res)
                if(res.data.retCode == 200){
                    // 刷新本表
                    this.$options.methods.searchBtn.bind(this)()
                    // 分拣台管理刷新工作包任务列表
                    this.$bus.$emit('sortManDoGzbsmData','reTable')
                    this.$Alert({
                        title: "成功",
                        message: res.data.message,
                        type: "success",
                    });
                }else{
                    this.$Alert({
                        title: "失败",
                        message: res.data.message,
                        type: "error",
                    });
                }
            })
        },
        offLineBtn(){
            sysSortTableOffline({

            }).then((res)=>{
                console.log('下线',res)
                if(res.data.retCode == 200){
                    // 刷新本Table
                    this.$options.methods.searchBtn.bind(this)()
                    // 分拣台管理刷新工作包任务列表
                    this.$bus.$emit('sortManDoGzbsmData','reTable')
                    this.$Alert({
                        title: "成功",
                        message: res.data.message,
                        type: "success",
                    });
                }else{
                    this.$Alert({
                        title: "失败",
                        message: res.data.message,
                        type: "error",
                    });
                }
            })
        }
    },
    mounted(){
        this.$options.methods.searchBtn.bind(this)()
    }
}
</script>
<style scoped>
.sortingTableBox {
    width: 100%;
}
.tableBOx {
    width: 100%;
    text-align: center;
}
</style>